package com.serviceImpl;

import com.javabean.Role;
import com.javabean.RolePermission;
import com.mapper.RoleMapper;
import com.service.RoleService;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @Author: 张波
 * @Time: 2025/8/28 14:33
 */
@Service
public class RoleServiceImpl implements RoleService {

	private final RoleMapper roleMapper;

	public RoleServiceImpl(RoleMapper roleMapper) {
		this.roleMapper = roleMapper;
	}

	/**
	 *
	 * @return 返回权限查询结果
	 */
	@Override
	public List<Role> findAll() {
		return roleMapper.selectAll();
	}
	/**
	 *
	 * @param id 传入id
	 * @return 返回返回角色详细信息
	 */
	@Override
	public Role show(int id) {
		return roleMapper.selectR_P(id);
	}

	/**
	 *
	 * @param role 传入角色对象
	 */
	@Override
	public void addRole(Role role) {
		roleMapper.insertRole(role);
	}

	/**
	 *
	 * @param id 传入要删除角色的id
	 */
	@Override
	public void deleteRole(int id) {
		roleMapper.deleteRole(id);
	}

	/**
	 *
	 * @param role 传入要修改的对象
	 */
	@Override
	public void updateRole(Role role) {
		roleMapper.updateByRid(role);
	}

	/**
	 *
	 * @param rolePermission 传入角色权限对象
	 */
	@Override
	public void permissionAdd(RolePermission rolePermission) {
		roleMapper.deleteByRid(rolePermission.getRid());
		roleMapper.insertR_P(rolePermission);
	}
}
